package com.sn.controller;

import com.sn.core.component.page.Pagination;
import com.sn.core.http.CommRequest;
import com.sn.model.Gift;
import com.sn.service.GiftService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by qingshengzheng on 18/3/30.
 */
@RequestMapping(value = "gift")
@Controller
@EnableAutoConfiguration
public class GiftController extends BaseController {
    @Resource
    private GiftService giftService;

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object addSchool(@RequestBody CommRequest<Gift> giftCommRequest) {
        giftService.addGift(giftCommRequest.getData());
        return responseJson(null);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object updateGift(@RequestBody CommRequest<Gift> giftCommRequest) {
        giftService.updateGift(giftCommRequest.getData());
        return responseJson(null);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object deleteGift(@RequestBody CommRequest<Gift> giftCommRequest) {
        giftService.deleteGift(giftCommRequest.getData().getId());
        return responseJson(null);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/query")
    @ResponseBody
    public Object queryGift(@RequestBody CommRequest<Gift> giftCommRequest) {
        Pagination pagination = giftService.queryGifts(giftCommRequest.getData());
        return responseJson(pagination);
    }
}
